<?php

  //////////////////////////////////////////////////////////////////
  // OrbitFAQ                                                     //
  // ---------                                                    //
  //                                                              //
  // Orbit FAQ was solely written and developed by Orbit Services //
  // http://www.orbitservices.net                                 //
  //                                                              //
  // Access the Forum here:                                       //
  // http://forums.orbitservices.net/index.php?c=4                //
  //                                                              //
  // OrbitFAQ utilises the following opensource projects/classes; //
  //  + Fckeditor - http://www.fckeditor.net                      //
  //  + Smarty Template Engine - http://smarty.php.net            //
  //  + Swift Email Class - http://www.swiftmailer.org/           //
  //  + OWASP PHP Filter Project - http://www.owasp.org           //
  //  + MySQL Search Class by Stephen Bartholomew                 //
  //                                                              //
  //////////////////////////////////////////////////////////////////


  /* -- TO BE REMOVED

DROP TABLE `orbitfaq_stats`;
CREATE TABLE `orbitfaq_stats` (
  `id` int(9) unsigned NOT NULL auto_increment,
  `phpsessid` varchar(120) NULL,
  `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ip` varchar(15) NOT NULL,
  `f_id` int(9) NULL,
  `c_id` int(9) NULL,
  `full_url` varchar(255) NULL,
  `user_agent` varchar(120) NULL,
  `referer` varchar(120) NULL,
  PRIMARY KEY  (`id`)
) COMMENT='FAQ Statistics' AUTO_INCREMENT=1 ;

  */

    //Get our Stat Details
    $datetime = date("Y-m-d H:i:s"); // time of hit
    $referer = $_SERVER['HTTP_REFERER']; // which page referred to current page
    $ip = $_SERVER['REMOTE_ADDR']; // ip address of user - will be able to be blocked
    $user_agent = $_SERVER['HTTP_USER_AGENT']; // web browser being used
    $phpsessid = $PHPSESSID; // PHP Session ID
    $full_url = "http://" .$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; // page url
    $f_id = sanitize_paranoid_string($_GET['faq']); // Selected FAQ
    $c_id = sanitize_paranoid_string($_GET['ca']); // Selected Category
    $qn_id = sanitize_paranoid_string($_GET['qn']); // Selected Question

    // Lets check if the PHPSESSID is available
    // this is done because the first page viewed will
    // not have a session applied, so we reload the page
    if(!isset($phpsessid))
      {
        // Redirect them back to the current page
        header( "Location: $full_url" ) ;
        exit;
      }

      // Identify the Web Browser Used by the user.
      if((ereg("Nav", getenv("HTTP_USER_AGENT"))) || (ereg("Gold", getenv("HTTP_USER_AGENT"))) || (ereg("X11", getenv("HTTP_USER_AGENT"))) || (ereg("Mozilla", getenv("HTTP_USER_AGENT"))) || (ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND (!ereg("Firefox", getenv("HTTP_USER_AGENT")) AND (!ereg("MSIE", getenv("HTTP_USER_AGENT")) AND (!ereg("Konqueror", getenv("HTTP_USER_AGENT")))))) $browser = "Netscape";
      elseif(ereg("MSIE 4", getenv("HTTP_USER_AGENT"))) $browser = "Internet Explorer 4";
      elseif(ereg("MSIE 5", getenv("HTTP_USER_AGENT"))) $browser = "Internet Explorer 5";
      elseif(ereg("MSIE 6", getenv("HTTP_USER_AGENT"))) $browser = "Internet Explorer 6";
      elseif(ereg("MSIE 7", getenv("HTTP_USER_AGENT"))) $browser = "Internet Explorer 7";
      elseif(ereg("Firefox", getenv("HTTP_USER_AGENT"))) $browser = "Firefox";
      elseif(ereg("Lynx", getenv("HTTP_USER_AGENT"))) $browser = "Lynx";
      elseif(ereg("Opera", getenv("HTTP_USER_AGENT"))) $browser = "Opera";
      elseif(ereg("WebTV", getenv("HTTP_USER_AGENT"))) $browser = "WebTV";
      elseif(ereg("Konqueror", getenv("HTTP_USER_AGENT"))) $browser = "Konqueror";
      elseif((eregi("bot", getenv("HTTP_USER_AGENT"))) || (ereg("Google", getenv("HTTP_USER_AGENT"))) || (ereg("Slurp", getenv("HTTP_USER_AGENT"))) || (ereg("Scooter", getenv("HTTP_USER_AGENT"))) || (eregi("Spider", getenv("HTTP_USER_AGENT"))) || (eregi("Infoseek", getenv("HTTP_USER_AGENT")))) $browser = "Bot";
      else $browser = "Other";
      $user_agent = "$browser";


    // Add our stat
    $query_add = "INSERT INTO `orbitfaq_stats` (
        `datetime`,
        `phpsessid`,
        `ip`,
        `f_id`,
        `c_id`,
        `full_url`,
        `user_agent`,
        `referer`
      )VALUES(
        '$datetime',
        '$phpsessid',
        '$ip',
        '$f_id',
        '$c_id',
        '$full_url',
        '$user_agent',
        '$referer'
      );

    ";

    $result_add = $faqsql_query ($query_add)OR DIE( "$sql_query_error $query_add");

?>